import { _decorator, Component, Node, RichText } from 'cc';
import { EventManager } from '../event/EventManager';
import { UIManager } from './UIManager';
import { PrefabEnum } from './PrefabEnum';
import { NoticeList } from './NoticeList';
const { ccclass, property } = _decorator;

@ccclass('Notice')
export class Notice extends Component {
    @property(RichText)
    richText:RichText

    msgList: any[] = []

    start() {
        EventManager.instance.on(EventManager.EventType.Notice, this.onNotice, this)
        this.node.on(Node.EventType.TOUCH_END, this.onClick, this)
    }

    onNotice(list){
        this.msgList = this.msgList.concat(list)
        console.log(this.msgList)
        let msg = this.msgList[this.msgList.length - 1]
        this.richText.string = `<b><color=#F2E8CF>【${msg.fn}】${msg.msg}</color></b>`
    }

    async onClick(){
        let ui = await UIManager.instance.openUI(PrefabEnum.NoticeList)
        ui.getComponent(NoticeList).setData(this.msgList)
    }
}


